#include <bits/stdc++.h>
using namespace std;
int l[100001],r[100001],lim[100001],sum[1000001],cnt,pre[100001];
struct node
{
    int l,r;
}a[100001],yyx[100001];
bool cmp(node x,node y)
{
    if(x.l!=y.l) return x.l<y.l;
    return x.r>y.r;
}
int findd(int x,int y)
{
    int l=1,r=x,ans,mid;
    while(l<=r)
    {
        mid=(l+r)>>1;
        if(mid*1ll*y>x) r=mid-1;
        else ans=mid,l=mid+1;
    }
    return ans;
}
void cal(int v,int d,int y,int V,int L,int id)
{
    if(d==0)
    {
        if(v>V) l[id]=y,r[id]=L+1;
        else l[id]=L,r[id]=-1;
        return;
    }
    if(d>0)
    {
        if(v>V)
        {
            l[id]=y,r[id]=L+1;
            return;
        }
        int dt=V*V-v*v,ddt=2*d,dda=dt*1ll*1.0/ddt;
        double da=dt*1.0/ddt;
        l[id]=dda+1+y,r[id]=L+1;
        return ;
    }
    if(d<0)
    {
        if(v<=V) l[id]=L,r[id]=-1;
        int dt=V*V-v*v,ddt=2*d,dda=dt*1ll*1.0/ddt;
        l[id]=y;
        if(dt%ddt==0) r[id]=dda-1+y;
        else r[id]=dda+y;
    }
}
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int n,m,L,V,T,d,x,y,ans,Yangl,Yangr;
    cin>>T;
    while(T--)
    {
        cin>>n>>m>>L>>V,memset(sum,0,sizeof sum);
        for(int i=1;i<=n;i++) cin>>y>>x>>d,cal(x,d,y,V,L,i);
        for(int i=1;i<=m;i++) cin>>lim[i],sum[lim[i]]++;
        ans=cnt=0;
        for(int i=1;i<=L;i++) sum[i]+=sum[i-1];
        for(int i=1;i<=n;i++)
        {
            if(l[i]>r[i]) continue;
     //       cout<<l[i]<<' '<<r[i]<<' '<<sum[min(r[i],L)]-(l[i]? sum[l[i]-1]:0)<<"\n";
            if(sum[min(r[i],L)]-(l[i]? sum[l[i]-1]:0)>0) a[++ans].l=l[i],a[ans].r=min(r[i],L);
        }
        cout<<ans<<' ';
        sort(a+1,a+1+ans,cmp);
        for(int i=1;i<=ans;i++) pre[i]=i-1;
        for(int i=1;i<=ans;i++)
        {
            for(int j=pre[i];j;j=pre[j])
            {
                if(a[j].l<=a[i].l&&a[i].r<=a[j].r) pre[i]=pre[j];
                else break;
            }
        }
        for(int i=ans;i;i=pre[i]) yyx[++cnt].l=a[i].l,yyx[cnt].r=a[i].r;
        reverse(yyx+1,yyx+1+cnt);
        int i;
        ans=0,Yangl=0,Yangr=0;
   //     for(i=1;i<=cnt;i++) cout<<yyx[i].l<<' '<<yyx[i].r<<"\n";
        for(i=1;i<=cnt;)
        {
            if(!(Yangr<yyx[i].l)&&sum[Yangr]-sum[max(Yangl,yyx[i].l-1)]>0)
            {
                i++;
                continue;
            }
            if(i==cnt||yyx[i].r<yyx[i+1].l||sum[yyx[i].r]-(yyx[i+1].l? sum[yyx[i+1].l-1]:0)<1) i++;
            else Yangr=yyx[i].r,Yangl=yyx[i+1].l,i+=2;
            ans++;
        }
        cout<<m-ans<<"\n";
    }
    return 0;
}
